home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
clm89nov.arc
/
STITT.C
< prev
next >
Wrap
Text File
|
1989-12-25
|
7KB
|
200 lines
Listing 1 - This sample C program illustrates how an application can
interface with the PC-MOS operating system.
/*
tref.c - sample program for PC-MOS Tech Ref
(c) Copyright 1989 The Software Link, Incorporated
*/
/* === Include files ===================*/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <bios.h>
#define tcbid 0x0010 /*dw task id (task0 = 0, task1 = 1, etc.) */
/*=== Macros ==========================*/
#define extcall int86x(extvect,®s,®s,&sregs)
#define i21call int86x(0x21,®s,®s,&sregs)
/*=== Typedefs ========================*/
typedef unsigned char byte;
typedef int word;
#define ofs 0
#define seg 1
typedef union {
int hlf[2]; /* access to each half of the pointer */
unsigned char far *bptr; /* use the pointer for a byte operation */
unsigned int far *wptr; /* use the pointer for a word operation */
void far *vptr; /* used for pointer to pointer copies */
long longint; /* used for double word numbers */
} dword;
/*=== Structures ======================*/
/*
the following structure outlines the data fields which must
be provided for the addtask API function call
*/
typedef struct {
word tsize; /* task size */
word tid; /* task id */
byte tclass; /* task class */
dword tbatch; /* task startup batchfile */
dword tdriver; /* task terminal driver */
word tport; /* task port */
dword tbaud; /* task baud rate */
dword tmemtot; /* total ext mem (RETURN) */
dword tmemalc; /* ext mem allocated (RETURN) */
word tsmpal; /* task smp allocate (RETURN) */
word tsmpsiz; /* task smp size (RETURN) */
word tpercent; /* task percent heap (RETURN) */
byte tres[3]; /* reserved */
} add_data;
/*=== Global variables ================*/
union REGS regs; struct SREGS sregs;
word extvect; /* vector number for extended services */
add_data addparm; /* declare an add_data structured variable */
char strtbat[9] = ""; /* pointer to startup batch file */
/*=== Subroutines =====================*/
/*
;- WORD_FROM_TCB -------------------------------------------------------;
; entry parms: tcb segment and offset ;
; exit parms: word from tcb ;
;-----------------------------------------------------------------------;
*/
word word_from_tcb(word tseg, word tofs) {
dword xptr;
xptr.hlf[seg] = tseg;
xptr.hlf[ofs] = tofs;
return(*xptr.wptr);
}
/*
;- GET_VECTS -----------------------------------------------------------;
; entry parms: none ;
; exit parms: the global variable extvect is initialized ;
; ;
; NOTE: the extvect pointer should not be considered valid until after ;
; the ismos procedure has been used to verify that MOS is the OS. ;
;-----------------------------------------------------------------------;
*/
void get_vects() {
extvect = 0x38; /* default choice */
regs.x.ax = 0x3000;
regs.x.bx = 0x3000; /* ax == bx == cx == dx to get */
regs.x.cx = 0x3000; /* the MOS version number */
regs.x.dx = 0x3000; /* if >= 4.00, use vect D4 */
int86(0x21,®s,®s);
if(regs.h.al >= 4 && regs.h.al >= 0) extvect = 0xd4;
}
/*
;- ISMOS ---------------------------------------------------------------;
; entry parms: none ;
; exit parms: returns == 0 if the OS is MOS ;
; returns !=0 if not ;
; ;
; NOTES: Verify that this program is running under the PC-MOS ;
; operating system before MOS specific system calls are made. ;
;-----------------------------------------------------------------------;
*/
int ismos() {
word mosver;
regs.x.ax = 0x3000;
regs.x.bx = 0x3000;
regs.x.cx = 0x3000;
regs.x.dx = 0x3000;
mosver = int86(0x21,®s,®s);
regs.x.ax = 0x3099;
return(mosver == int86( 0x21,®s,®s));
}
/*
;- DISP_STATS ----------------------------------------------------------;
; entry parms: a pointer to the addparm structure ;
; a pointer to the new task's tcb ;
; exit parms: none ;
; ;
; NOTES: this procedure displays the memory statistics after a call ;
; is made to the addtask api function. ;
;-----------------------------------------------------------------------;
*/
void disp_stats(int newtcb, add_data *addstruc) {
union {
int xint;
char xchar[2];
} x;
printf("Starting task # %d\n",word_from_tcb(newtcb,tcbid));
if(addstruc->tmemtot.longint != 0) { /* if memory management exists */
printf("Total extended memory %ldK\n",addstruc->tmemtot.longint * 4);
printf("Extended memory allocated %ldK\n",addstruc->tmemalc.longint * 4);
}
printf("Total SMP memory %dK\n",((long)addstruc->tsmpsiz * 16)/1024);
printf("SMP memory allocated %dK\n",((long)addstruc->tsmpal * 16)/1024);
x.xint = addstruc->tpercent;
printf("Percent of SMP in use %c%c%%\n",x.xchar[0],x.xchar[1]);
}
/*=== Main code ===========================*/
main() {
dword xptr;
if(ismos() != 0) {
printf("\nPC-MOS must be the operating system\n");
exit(1);
}
get_vects();
/*
At this point, it has been verified that the
operating system is PC-MOS so it is safe to
use MOS specific function calls and interface to
MOS's data structures
*/
/* add a background task */
addparm.tsize = 32; /* 32K task size */
addparm.tid = 0; /* let MOS pick the id */
addparm.tclass = ' '; /* no security */
addparm.tbatch.vptr = strtbat;
addparm.tdriver.longint = 0;
addparm.tport = 0;
addparm.tbaud.longint = 0;
xptr.vptr = &addparm;
regs.x.si = xptr.hlf[ofs];
sregs.ds = xptr.hlf[seg];
regs.h.ah = 0x22;
extcall;
if(regs.x.cflag == 1) {
printf("\nError # %d adding background task\n",regs.x.ax);
exit(1);
}
disp_stats(sregs.es,&addparm);
}